package com.dkts.oil.mysql;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class CodeGeneratorV2 {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://211.159.175.30:18123/uam2_prod?createDatabaseIfNotExist=false&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC",
                        "root", "dgts@Ro0t")
                .globalConfig(builder -> {
                    builder.author("heguanglong") // 设置作者名称
                            .outputDir("D:/dkSpace/code/uam2-web-api-20250415/uam2-web-api" + "/src/main/java") // 设置生成路径
                            .disableOpenDir(); // 生成后不打开文件夹
                })
                .packageConfig(builder -> {
                    builder.parent("com.uam") // 设置父包名
//                            .moduleName("tasks") // 设置模块名
                            .entity("db.model.entity")
                            .mapper("db.mapper")
                            .service("service.plan")
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml,"D:/dkSpace/code/uam2-web-api-20250415/uam2-web-api" + "/src/main/resources/mapper"));
                    builder.controller("com.uam.web.controller.plan");
                    // 设置XML生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("plan_task_run_result") // 设置要生成的表
                            .addTablePrefix("t_")
                            .entityBuilder()
                            .enableLombok() // 启用 Lombok
                            .naming(NamingStrategy.underline_to_camel) // 表名下划线转驼峰
                            .columnNaming(NamingStrategy.underline_to_camel) // 字段名下划线转驼峰
                            .enableTableFieldAnnotation()
                            .mapperBuilder().enableBaseResultMap() // 启用 BaseResultMap
                            .enableBaseColumnList(); // 启用 BaseColumnList;// 启用字段注解; // 过滤表前缀

                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎
                .execute();
    }
}
